Skip to content

Conversation

@spahnke
Copy link
Collaborator

@spahnke spahnke commented Jun 21, 2021

Follow up on #95. This is a) more efficient because we only ever create one Persistent per managed object while it is alive and b) prevents a crash when the same managed object is wrapped repeatedly.

Code for Fiddling that crashed before:

public class Product
{
    public Product()
    {
        Price = new Random().NextDouble();
    }

    public double Price { get; }
}

public class ProductFactory
{
    public ProductFactory()
    {
        Product = new Product();
    }

    public Product Product { get; } // we always return the same object reference here
}

// ...

context.SetParameter("productFactory", new ProductFactory());
context.Run(@"
for (let i = 0; i < 10_000_000; i++) {
    const product = productFactory.Product;
    product.Price;
}
");

spahnke added 2 commits June 21, 2021 10:27
If the object has already been wrapped just return a new Local handle from the Persistent. Only if the Persistent handle is empty create a new one.
@spahnke spahnke requested a review from oliverbock June 21, 2021 09:23
@oliverbock oliverbock merged commit 9fb8aee into JavascriptNet:master Jun 21, 2021
@spahnke spahnke deleted the reuse-persistent branch June 22, 2021 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants